package xing.design.pattern.create.factory.simple;

import xing.design.pattern.create.factory.IBasic;
import xing.design.pattern.create.factory.Basic1;
import xing.design.pattern.create.factory.Basic2;

/**
 * 简单工厂模式，简单的只有一个工厂类，无实现类
 *
 * @author xing
 * @date 2023/2/7 22:54:19
 */
public class SimpleBasicFactory {
    public static <T extends IBasic> IBasic createBasic(Class<T> clazz) throws InstantiationException, IllegalAccessException {
        return clazz.newInstance();
    }

    public static IBasic creatBasic(String name) {
        switch (name) {
            case "basic1":
                return new Basic1();
            case "basic2":
                return new Basic2();
            default:
                return null;
        }
    }
}
